
package com.scs.application.modules.upms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.scs.application.core.service.BaseServiceImpl;
import com.scs.application.core.utils.StringUtils;
import com.scs.application.modules.upms.entity.SerialOwner;
import com.scs.application.modules.upms.mapper.SerialOwnerMapper;
import com.scs.application.modules.upms.request.SerialOwnerQueryRequest;
import com.scs.application.modules.upms.service.SerialOwnerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 编号规则主体 service 实现
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class SerialOwnerServiceImpl extends BaseServiceImpl<SerialOwnerMapper, SerialOwner> implements SerialOwnerService {

    @Override
    public List<SerialOwner> list(SerialOwnerQueryRequest request) {
        List<SerialOwner> list = this.list(getQueryWrapper(request));
        return list;
    }

    @Override
    public IPage<SerialOwner> page(SerialOwnerQueryRequest request) {
        IPage page = this.page(request.getPage(), getQueryWrapper(request));
        return page;
    }

    private QueryWrapper<SerialOwner> getQueryWrapper(SerialOwnerQueryRequest request) {
        return Wrappers.<SerialOwner>query()
                .eq(StringUtils.isNotBlank(request.getRuleId()),"rule_id", request.getRuleId())
                .orderByDesc("gmt_modified");
    }
}
